﻿@model IEnumerable<ChequeBook>

@{
    ViewBag.Title = "ธุรกรรมธนาคาร";
    ViewBag.Descr = "ทะเบียนเช็ค";
}

@using (Html.BeginForm("DeleteAll", "ChequeBook", FormMethod.Post, new { id = "form" }))
{
    @Html.AntiForgeryToken()
    
    <div class="row-fluid">
        <div class="block-button-menu-above">
            @Html.ButtonAdd()
            @Html.ButtonDeleteAll()
        </div>

        <div class="alert-error">@Html.ValidationSummary()</div>

        <div class="row-fluid">
            <div class="table-header span12">
                <div class="span10">@ViewBag.Title</div>
                @Html.Partial("_ExportButton")
            </div>
        </div>

        <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
            <thead>
                <tr>
                     <th class="center" style="width: 50px;">
                        <label>
                            <input type="checkbox" />
                            <span class="lbl"></span>
                        </label>
                    </th>

                    <th>สมุดบัญชีเงินฝาก</th>
                    <th>เลขที่สมุดเช็ค</th>
                    <th>เเช็คใบแรก</th>
                    <th>เช็คใบสุดท้าย</th>
                    <th>สถานะสมุดบัญชีเงินฝาก</th>
                    <th></th>

                </tr>
            </thead>

            <tbody>
                @foreach (var m in Model)
                {
                    <tr>
                        <td class="center">
                            <label>
                                <input type="checkbox" name="deleteIds" value="@(m.ChequeBookId)" />
                                <span class="lbl"></span>
                            </label>
                        </td>

                        <td>@Html.DisplayFor(modelItem => m.MasBankAccount.Name)</td>
                        <td>@Html.DisplayFor(modelItem => m.Code)</td>
                        <td>@Html.DisplayFor(modelItem => m.StartChequeNo)</td>
                        <td>@Html.DisplayFor(modelItem => m.EndChequeNo)</td>
                        @if(m.ChequeBookStatus == "1") { 
                        <td>ใช้งานอยู่</td>}
                        else{
                            <td></td>
                        }
                        <td class="td-actions">
                            @Html.Partial("_ButtonMenuEachRow", new ExportGrid
                                {
                                    Id = m.ChequeBookId,
                                    DetailsUrl = Url.Action("Details") + "/" + m.ChequeBookId,
                                    EditUrl = Url.Action("Edit") + "/" + m.ChequeBookId,
                                    DeleteUrl = Url.Action("Delete") + "/" + m.ChequeBookId,

                                })
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}

@section scripts {
	<script type="text/javascript">
	    $(function () {
	        var oTable1 = $('#table').dataTable({
	            "aoColumns": [
                    { "bSortable": false },
                    null,
                    null,
                    null,
                    null,
                    null,
                    { "bSortable": false }
	            ]
	        });

	        $('table th input:checkbox').on('click', function () {
	            var that = this;
	            $(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function () {
				    this.checked = that.checked;
				    $(this).closest('tr').toggleClass('selected');
				});

	        });

	        $('[data-rel=tooltip]').tooltip();

	        $("form").submit(function () {
	            var currentForm = this;
	            bootbox.confirm(function (result) {
	                var _result = result;
	                if (result) {
	                    $.ajax({
	                        url: "DeleteAll",
	                        type: "post",
	                        dataType: "json",
	                        data: $(currentForm).serialize(),
	                        success: function (result) {
	                            if (result.success) {
	                                location.reload();
	                            } else {
	                            }
	                        }
	                    });
	                }
	            })
	            return false;
	        });
	    })

	</script>
}